package zhouyang;

import java.util.concurrent.*;

public class MyThreadPoolDemo {
    public static void main(String[] args) {
        ExecutorService threadPool1 = Executors.newFixedThreadPool(5);
        ExecutorService threadPool2 = Executors.newSingleThreadExecutor();
        ExecutorService threadPool3 = Executors.newCachedThreadPool();
        ExecutorService threadPool = new ThreadPoolExecutor(2,5,30L,TimeUnit.SECONDS,new LinkedBlockingQueue<Runnable>(4) );
        try {
//            模拟10个人顾客办理业务，目前池子里有5个工作人员提供服务
            for (int i = 1; i <=10; i++) {
//                try {TimeUnit.MILLISECONDS.sleep(50);
//                }catch (InterruptedException e){
//                    e.printStackTrace(); }
               threadPool1.execute(()->{
                   System.out.println(Thread.currentThread().getName()+"\t 办理业务");
               });
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            threadPool1.shutdown();
        }
    }
}
